import pymysql
'''
链接mysql数据库
'''

db = pymysql.connect(host='localhost',user='root',password='123456',db='mysql',charset='utf8mb4',cursorclass=pymysql.cursors.DictCursor)

cursor = db.cursor()

sql = 'select version()'

cursor.execute(sql)

data = cursor.fetchall()

db.close()

print(data)